<?php

namespace console\migrations;

use console\migrations\Base;

/**
 * Handles the creation of table `{{%svn_file}}`.
 */
class M200813202653CreateSvnFileTable extends Base
{

    protected string $tableName = '{{%svn_file}}';
    protected string $tableComment = '';

    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable($this->tableName, [
            'id'      => $this->primaryKey(),
            'svn_id'  => $this->integer(11)->notNull(),
            'file_id' => $this->integer(11)->notNull(),
            'comment' => $this->string(255)->notNull()->defaultValue('')->comment('简述'),
            'detail'  => $this->text()->comment('详述'),
        ], $this->tableOptions);

        $this->addForeignKey('fk-svn_file-svn', $this->tableName, 'svn_id', '{{%svn}}', 'id', 'CASCADE');
        $this->addForeignKey('fk-svn_file-file', $this->tableName, 'file_id', '{{%file}}', 'id', 'CASCADE');
        $this->createIndex('k-svn-file', $this->tableName, ['svn_id', 'file_id']);
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropForeignKey('fk-svn_file-svn', $this->tableName);
        $this->dropForeignKey('fk-svn_file-file', $this->tableName);
        $this->dropIndex('k-svn-file', $this->tableName);
        $this->dropTable('{{%svn_file}}');
    }
}
